#coding:utf-8
from lovewith.website.models import Role
from lovewith.utils.mtcache import MtCache


#商家角色
class AttachRoleApi:
    def __init__(self):
        pass

    @staticmethod
    def check_data(role_id):
        role_data = Role.objects.filter(id = int(role_id))
        if role_data.exists():
            return role_data[0]
        else:
            return False

    #全部角色列表
    @staticmethod
    def get_all():
        role_data = MtCache('role').get()
        if not role_data:
            role_data = []
            role_filte_data = Role.objects.all().order_by('-sort')
            for role in role_filte_data:
                role_data.append({'id': role.id, 'name': role.name})

            MtCache('role').set(role_data)

        return role_data





















